package com.xlh.support.backup.job;

import com.xlh.service.course.ChapterService;
import com.xlh.support.backup.dao.BackupMapper;
import com.xlh.support.backup.dao.helper.BackupMapperHelper;
import com.xlh.support.backup.domain.Backup;
import com.xlh.support.backup.domain.BackupExample;
import com.xlh.support.backup.service.BackupService;
import com.xlh.virtualization.constant.ContextTypeEnum;
import com.xlh.virtualization.dao.helper.ContainerMapperHelper;
import com.xlh.virtualization.domain.Container;
import com.xlh.virtualization.service.ConfigService;
import com.xlh.virtualization.service.ContainerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 自动备份
 *
 * @author cheer
 */
@Component
@Slf4j
public class AutoBackupJob {

    @Autowired
    private BackupMapperHelper backupMapperHelper;

    @Autowired
    private BackupService backupService;

    /**
     * 每天凌晨1点执行删除容器定时任务
     */
    @Scheduled(cron = "0 0 1 * * *")
    public void autoBackup() {
        try {
            Backup backup = backupMapperHelper.getBackup();
            if (backup != null && backup.getAutoBackup()) {
                log.info("开始执行定时备份");

                backupService.manualBackup();

                log.info("执行定时备份完毕");
            }
        } catch (Exception e) {
            log.error("执行定时备份异常", e);
        }
    }

}
